package cst.neu.neufooddemo.model;


import cst.neu.neufooddemo.beans.LoginBean;
import cst.neu.neufooddemo.listener.RetrofitListener;
import cst.neu.neufooddemo.common.Constans;
import cst.neu.neufooddemo.services.UserService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by liningning on 2017/10/21.
 */

public class UserModel extends RetrofitBaseModel {
//    private Retrofit retrofit;
//    private UserService service;
//
//    public UserModel()
//    {
//        retrofit = new Retrofit.Builder()
//                .baseUrl(Constans.BASE_URL)
//                .addConverterFactory(GsonConverterFactory.create())
//                .build();
//        service = retrofit.create(UserService.class);
//    }
//
//    public void userLogin(String username, String password, final RetrofitListener listener)  {
//        Call call=service.userLogin(username, password);
//        Callback<LoginBean> callback = new Callback<LoginBean>() {
//            @Override
//            public void onResponse(Call<LoginBean> call, Response<LoginBean> response) {
//                listener.onSuccess(response.body(),1);
//            }
//            @Override
//            public void onFailure(Call<LoginBean> call, Throwable t) {
//                listener.onFail();
//            }
//        };
//        call.enqueue(callback);
//    }
    private UserService userService;
    public UserModel(){
        this.userService=retrofit.create(UserService.class);
    }
    public void userLogin(String username, String password, final RetrofitListener listener){
        Call call=userService.userLogin(username,password);
        bindCallback(call,listener);
    }
    public void register(String username,String userpass,String mobilenum,String address,String comment ,final RetrofitListener listener  ){
        Call call=userService.register(username,userpass,mobilenum,address,comment);
        bindCallback(call,listener);
    }
}

